package cn.demoa.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button btnStarB;
    private long lastPressTime = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnStarB = findViewById(R.id.btn_Star_b);
        btnStarB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,ActivityB.class);
                startActivity(intent);
            }
        });
    }
    public void onBackPressed(){
        long currentPressTime = System.currentTimeMillis();

        if (currentPressTime - lastPressTime >2000){
            lastPressTime = currentPressTime;
            Toast.makeText(MainActivity.this,
                    "再按一次退出",Toast.LENGTH_SHORT).show();
        }else {
            super.onBackPressed();
        }
    }
}
